Repository Public
1import { join } from "node:path";2import { getCourse, getFigureFile, importDir } from "@/lib/content";3import { env } from "@/lib/env";4import { notFoundResponse, serveBytes, serveObject } from "@/lib/serve";5import { FsStorage } from "@/modules/storage";67export const dynamic = "force-dynamic";89/** Imported figures: /contenu/S01/figures/<file>.svg — served only if listed in a visible figures section. */10async function handle(request: Request, { params }: { params: Promise<{ path: string[] }> }) {11 const [sessionId, ...rest] = (await params).path;12 const session = (await getCourse()).sessions.find((s) => s.id === sessionId);13 if (!session) return notFoundResponse();14 const file = await getFigureFile(session, rest.join("/")); // null unless the section is visible to the public15 if (!file) return notFoundResponse();16 const cache = env.mode === "preview" ? "private, no-store" : "public, max-age=3600";17 if ("bytes" in file) return serveBytes(file.bytes, "image/svg+xml", request, { cache });18 return serveObject(new FsStorage(join(importDir(), "sessions")), file.storageKey, request, { cache });19}20export { handle as GET, handle as HEAD };21